import { Injectable, Inject } from '@angular/core';
import { HttpInterceptor, HttpRequest, HttpHandler, HttpEvent } from '@angular/common/http';
import { Observable } from 'rxjs';
import { API_URL_TOKEN } from '../request.token';

@Injectable({
  providedIn: 'root'
})
export class RequestService implements HttpInterceptor {

  constructor(
    @Inject(API_URL_TOKEN) private apiUrl: string,
  ) {
    console.log(12312321312321);
  }

  intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    console.log(req);
    const cpReq = req.clone({
      url: this.apiUrl + req.url,
      body: JSON.stringify(req.body),
      withCredentials: true
    });
    return next.handle(cpReq);
  }
}
